<?php
/**
 * @property integer $id
 * @property integer $dev_id
 * @property string $name
 * @property string $src
 *
 * The followings are the available model relations:
 * @property Dev $dev
 */
class DevFiles extends CActiveRecord
{
	public function tableName()
	{
		return 'dev_files';
	}

	public function rules()
	{
		return array(
			array('dev_id, name, src', 'required'),
			array('dev_id', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>100),
			array('src', 'length', 'max'=>255),
			array('id, dev_id, name, src', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
			'dev' => array(self::BELONGS_TO, 'Dev', 'dev_id'),
		);
	}

	public function attributeLabels()
	{
		return array(
			'id' => 'ИД',
			'dev_id' => 'Разработка',
			'name' => 'Файл',
			'src' => 'Путь',
		);
	}

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
    
    public function afterDelete()
    {
        if (parent::afterDelete()) {
            unlink($this->src);
            return true;
        } else {
            return false;
        }
    }
}
